import { create } from 'zustand';
import { devtools } from 'zustand/middleware';

interface AdminInfo {
  id: string;
  user_name: string;
  phone: string;
  create_time: string;
}

interface AdminInfoStore {
  adminInfo: AdminInfo;
  token: string;
}

interface AdminInfoStoreActions {
  setAdminInfo: (adminInfo: AdminInfo) => void;
  setToken: (token: string) => void;
}

const useAdminInfoStore = create(
  devtools<AdminInfoStore & AdminInfoStoreActions>((set) => ({
    adminInfo: JSON.parse(localStorage.getItem('adminInfo') || '{}') as AdminInfo,
    token: (localStorage.getItem('token') as string) || '',
    setAdminInfo: (adminInfo: AdminInfo) => set({ adminInfo }),
    setToken: (token: string) => set({ token }),
  }))
);

export default useAdminInfoStore;
